<template>
  <div class="content">
    <div
      class="body"
      :style="{
        backgroundImage: props.backgroundImg?.length ? `url('${props.backgroundImg[0].url}')` : ''
      }"
    >
      <div class="status-bar"></div>
      <div class="top">
        <div class="header">
          <img class="home" src="../../../../assets/images/home.png" alt="" />
          <img
            class="header-button"
            src="../../../../assets/images/Wechatsystem.png"
            alt=""
            srcset=""
          />
        </div>
      </div>
      <!-- <div class="title">
        <img class="text1" src="../../../../assets/images/text1.png" alt="" srcset="" />
        <img class="text2" src="../../../../assets/images/text2.png" alt="" srcset="" />
      </div>
      <div class="title-desc"> 折扣福利多 优惠享不停</div> -->
      <div class="list-wrapper">
        <div v-if="props.list.length > 0" class="list">
          <div class="item" v-for="couponItem in props.list" :key="couponItem.id">
            <div class="_left">
              <div class="couponType">
                {{
                  couponItem?.type === 1
                    ? '满减券'
                    : couponItem?.type === 2
                    ? '折扣券'
                    : couponItem?.type === 3
                    ? '单品券'
                    : couponItem?.type === 4
                    ? '新人券'
                    : couponItem?.type === 5
                    ? '霸王免单券'
                    : ''
                }}
              </div>
              <div v-if="couponItem?.type === 5" class="freeOfCharge">免单</div>
              <div v-else class="couponPriceBox">
                <div class="couponPrice_box">
                  <div class="couponPrice">{{ couponItem?.discounts }}</div>
                  {{ couponItem.discountsType === 1 ? '元' : '折' }}
                </div>
                <div class="couponRule">{{ convertText(couponItem) }}</div>
              </div>
              <div class="top-semicircular"></div>
              <div class="bottom-semicircular"></div>
            </div>
            <div class="_right">
              <div class="couponName_box">
                <div class="couponName">{{ couponItem.couponName }}</div>
                <div class="ruleButton">
                  使用规则
                  <div class="icon_questionMark">?</div>
                </div>
              </div>
              <div class="_remaining">{{ couponItem?.couponCount }}张</div>
            </div>
          </div>
        </div>
        <div v-else class="list no-list">
          <img class="no-data" src="../../../../assets/images/no-coupon.png" alt="" />
        </div>
      </div>
      <div class="button" style="margin-top: 167px">{{
        props.buttonName ? props.buttonName : '一键领取'
      }}</div>
      <img class="bottom" src="../../../../assets/images/Home-Indicator.png" alt="" srcset="" />
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  list: {
    type: Array,
    default() {
      return []
    }
  },
  backgroundImg: {
    type: Array,
    default() {
      return []
    }
  },
  buttonName: {
    type: String,
    default: ''
  }
})

/** 传入值返回优惠券规则 */
const convertText = (item) => {
  if (item.threshold) {
    return `满${item.threshold}元可用`
  } else if (!item.threshold && item.discountsType === 2) {
    return `无门槛`
  } else {
    return `无门槛立减`
  }
}
</script>

<style lang="scss" scoped>
.content {
  width: 375px;
  .status-bar {
    background-image: url('../../../../assets/images/Status-Bar.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    width: 375px;
    height: 44px;
  }
  .top {
    width: 375px;
    height: 44px;
    .header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 7px 7px 7px 18px;
      .header-button {
        width: 87px;
        height: 32px;
      }
      .home {
        width: 30px;
        height: 30px;
      }
    }
  }
  .body {
    padding-bottom: 13px;
    position: relative;
    height: 812px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    .title {
      margin-top: 24px;
      width: 100%;
      position: relative;
      height: 35px;
      img {
        width: 298px;
        height: 46px;
        margin-left: 49px;
        display: block;
      }
      .text2 {
        position: absolute;
        left: 3px;
        bottom: -3px;
        width: 287px;
        height: 35px;
      }
    }
    .title-desc {
      width: 230px;
      height: 35px;
      text-align: center;
      margin-top: 15px;
      border-radius: 10px;
      border: 1px solid #fff;
      background: rgba(138, 223, 75, 0.22);
      color: #488b16;
      font-family: 'HarmonyOS Sans';
      font-size: 20px;
      font-weight: 400;
      line-height: 35px;
      margin: 13px auto 17px;
    }
    .list-wrapper {
      width: 347px;
      max-height: 345px;
      margin: 125px auto 0;
      border-radius: 10px;
      background: #dbf8c6;
      box-shadow: 0px 4px 5px 0px rgba(0, 0, 0, 0.09);
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 14px 10px;
      overflow: hidden;
      &::after {
        content: '';
        width: 70px;
        height: 70px;
        background: #8adf4b;
        position: absolute;
        bottom: 0;
        left: 0;
        border-radius: 0 0 0 10px;
      }
      &::before {
        content: '';
        width: 70px;
        height: 70px;
        background: #8adf4b;
        position: absolute;
        top: 0;
        right: 0;
        border-radius: 0 10px 0 0;
      }
    }
    ::-webkit-scrollbar {
      display: none; /* 对于Chrome, Safari和Opera */
    }
    .list {
      width: 327px;
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      overflow-y: auto;
      border-radius: 10px;
      .item {
        flex-shrink: 0;
        position: relative;
        z-index: 2;
        width: 327px;
        height: 99px;
        background-image: url('../../../../assets/images/coupon-bg.png');
        background-size: 100% 100%;
        background-repeat: no-repeat;
        display: flex;
        align-items: center;
        overflow: hidden;
        &:not(:last-of-type) {
          margin-bottom: 10px;
        }
        ._left {
          position: relative;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          width: 106px;
          height: 97px;
          border-radius: 8px 0 0 8px;
          background: linear-gradient(
            90deg,
            rgba(138, 223, 75, 0.22) 0%,
            rgba(138, 223, 75, 0.08) 100%
          );
          z-index: 9;
          .couponType {
            width: 66px;
            height: 18px;
            line-height: 18px;
            color: #488b16;
            font-family: 'PingFang SC';
            font-size: 10px;
            font-weight: 400;
            position: absolute;
            left: 0;
            top: 0;
            text-align: center;
            border-radius: 8px 0px;
            background: linear-gradient(
              90deg,
              rgba(138, 223, 75, 0.6) 0%,
              rgba(138, 223, 75, 0) 100%
            );
          }

          .top-semicircular {
            position: absolute;
            top: -10px;
            right: -8px;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: #dbf8c6;
          }
          .bottom-semicircular {
            position: absolute;
            bottom: -10px;
            right: -8px;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: #dbf8c6;
          }
          .freeOfCharge {
            font-size: 24px;
            color: #488b16;
          }
          .couponPriceBox {
            display: flex;
            flex-direction: column;
            align-items: center;
            .couponPrice_box {
              display: flex;
              align-items: baseline;
              min-width: 28px;
              height: 34px;
              color: #488b16;
              font-size: 12px;
              .couponPrice {
                font-size: 28px;
              }
            }
            .couponRule {
              margin-top: 4px;
              min-width: 28px;
              height: 17px;
              font-size: 12px;
              color: #488b16;
            }
          }
        }
        ._right {
          flex: 1;
          display: flex;
          align-items: center;
          height: 98px;
          position: relative;
          z-index: 9;
          .couponName_box {
            width: 120px;
            white-space: normal;
            word-wrap: break-word;
            word-break: break-all;
            margin-left: 21px;
            .couponName {
              color: #000;
              font-family: 'PingFang SC';
              font-size: 15px;
              font-weight: bold;
            }
            .ruleButton {
              margin-top: 4px;
              display: flex;
              align-items: center;
              font-size: 12px;
              color: #00000080;
              .icon_questionMark {
                margin-left: 6px;
                font-size: 12px;
                width: 12px;
                height: 12px;
                text-align: center;
                line-height: 10px;
                border: 1px solid #00000050;
                border-radius: 100%;
              }
            }
          }
          ._remaining {
            position: absolute;
            right: -34px;
            top: 8px;
            font-size: 12px;
            color: #fff;
            width: 100px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            background: #ff714c;
            transform: rotate(45deg);
          }
        }
      }
    }
    .no-list {
      width: 330px;
      height: 210px;
      padding: 9px 8px;
      .no-data {
        position: relative;
        z-index: 2;
        width: 312px;
        height: 194px;
      }
    }
    .button {
      position: absolute;
      left: 50%;
      bottom: 47px;
      transform: translate3d(-50%, 0, 0);
      width: 314px;
      height: 40px;
      text-align: center;
      line-height: 40px;
      border-radius: 56px;
      background: #8adf4b;
      color: #fff;
      font-family: 'PingFang SC';
      font-size: 14px;
    }
  }
  .bottom {
    width: 375px;
    height: 34px;
    position: absolute;
    bottom: 0;
    left: 0;
  }
}
</style>
